package org.jackysoft.struts2.business;

import java.io.ByteArrayInputStream;
import java.util.Collection;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Namespace;
import org.jackysoft.entity.ArmMonthlyFinishedProductReporter;
import org.jackysoft.service.ArmMonthlyFinishedReporterService;
import org.jackysoft.util.HttpUtil;
import org.jackysoft.util.StringUtils;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

@Controller
@Namespace("/reporter/finished")
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
public class ArmMonthlyFinishedProductReporterAction extends
		ReporterCRUDAction<ArmMonthlyFinishedProductReporter> {

	/**
	 * 
	 */
	private static final long serialVersionUID = -4693049094182838125L;
	private ArmMonthlyFinishedProductReporter bean;
	private Collection<ArmMonthlyFinishedProductReporter> beans;
    private ArmMonthlyFinishedReporterService service;
	
	/**
	 * 重载默认的添加报表方法,月成品报表是根据日报表
	 * 自动生成的报表,添加报表.
	 * */
	public String genall() throws Exception {
		beans=service.generateAll();
		return "genall";
	}	
	
	/**
	 * 重载默认的添加报表方法,月成品报表是根据日报表
	 * 自动生成的报表,添加报表.
	 * */
	public String genwithdate() throws Exception {
		beans=service.generateAll(usedate);
		return "genall";
	}	

	public String openone() throws Exception{
		bean = service.get(year, month, department);
		return "openone";
	}
	
	public String download() throws Exception{
		byte[] bs =  service.export2Xls(year, month);
        contentType = HttpUtil.extToMimeType("xls");
        contentLength  =bs.length;
        upLoadFileName = StringUtils.toDownloadFileName(year+"年"+month+"生产月报.xls");
        inputStream = new ByteArrayInputStream(bs);
		return DOWNLOAD;
	}

	
	
	
	public ArmMonthlyFinishedReporterService getService() {
		return service;
	}

	@Resource
	public void setService(ArmMonthlyFinishedReporterService service) {
		this.service = service;
		this.setDataProvider(service);
	}


	public ArmMonthlyFinishedProductReporter getBean() {
		return bean;
	}


	public void setBean(ArmMonthlyFinishedProductReporter bean) {
		this.bean = bean;
	}


	public Collection<ArmMonthlyFinishedProductReporter> getBeans() {
		return beans;
	}


	public void setBeans(Collection<ArmMonthlyFinishedProductReporter> beans) {
		this.beans = beans;
	}
		

}
